<?php
/**
 * Created by PhpStorm.
 * User: Antique
 * Date: 2021/12/6
 * Time: 下午 10:04
 */
if (empty($_COOKIE['Token'])) {
    $pd = '1';
} else {
    $pd = '0';
}
$arr = explode('.', $_FILES['head_img']['name']);
$md5_head_img = $_COOKIE['Token'];
$suffix = '.' . $arr[count($arr) - 1];
if ($suffix == '.jpg' || $suffix == '.png') {
    $pd2 = '0';
    move_uploaded_file($_FILES['head_img']['tmp_name'], 'img/' . $md5_head_img . $suffix);
} else {
    $pd2 = '1';
}
?>
<!!DOCTYPE html>
<html>
<body>
<h1>你的头像是：</h1>
<img src="<?php echo('img/' . $md5_head_img . $suffix) ?>">
</body>
<script type="text/javascript">
    if (<?php echo $pd ?> == '1'
    )
    {
        alert('你还没登陆或者cookie失效');
        window.location.href = 'login.php';
    }
    if (<?php echo $pd2 ?> == '1'
    )
    {
        alert('你上传的不是规定格式的文件');
        window.location.href = 'user_function.php';
    }
</script>
</html>
